function showOne(id) {
    var a = { 'delete-p': 'pay-p', 'pay-p': 'delete-p' };
    $('#prompt-outer').style.display = 'block';
    $('#' + id).style.display = 'block';
    $('#' + a[id]).style.display = 'none';
}
var item;
(function() {
    var cancel = $$('.cancel');
    elesAddEvent(cancel, 'click', function() {
        $('#prompt-outer').style.display = 'none';
    })

})();
(function() {
    var logout = $('#logout');
    $('#logout').addEventListener('click', function(e) {
        new Ajax({
            url: '/logout',
            method: 'post',
            data: {},
            success: function(data) {
                if (data['success']) {
                    window.location.href = '/login';
                }
            }
        }).send();
    })
})();
var deleteF = (function() {
    return function(obj) {
        showOne('delete-p');
        item = obj;

    };
})();
eleAddEvent($('#d-con'), 'click', function() {
    var phone = item.parentNode.parentNode.getElementsByClassName('phone')[0].innerHTML;
    new Ajax({
        url: '/delete',
        method: 'post',
        data: { phone: phone },
        success: function(data) {
            if (data['success']) {
                $$('tbody')[0].removeChild(item.parentNode.parentNode);
                $('#prompt-outer').style.display = 'none';
            }
        }
    }).send();
});
var pay = (function() {
    return function(obj) {
        showOne('pay-p');
        item = obj;
    }
})();
eleAddEvent($('#p-con'), 'click', function() {
    var phone = item.parentNode.parentNode.getElementsByClassName('phone')[0].innerHTML;
    new Ajax({
        url: '/pay',
        method: 'post',
        data: { phone: phone },
        success: function(data) {
            if (data['success']) {
                item.setAttribute('disabled', true);
                item.parentNode.parentNode.getElementsByClassName('pay')[0].innerHTML = 1;
                $('#prompt-outer').style.display = 'none';
            }
        }
    }).send();
});